package com.acme.bankapp.server.command;

import com.acme.bankapp.domain.bank.Bank;

public class CommandFactory {
	private Bank bank;

	public CommandFactory(Bank bank) {
		this.bank = bank;
	}
	
	public Command createCommand(String message) {
		String cmd, arg;
		int separatorIdx = message.indexOf(' ');
		if (separatorIdx >= 0) {
			cmd = message.substring(0, separatorIdx);
			arg = message.substring(separatorIdx + 1);
		} else {
			cmd = message;
			arg = null;
		}
		
		switch(cmd) {
			case "add":
				return new AddClientCommand(bank, arg);
			case "list":
				return new ListCommand(bank, arg);
			case "echo":
				return new EchoCommand(arg);
			case "report":
				return new ReportCommand(bank, arg);
			case "exit":
				return new ExitCommand();
			default:
				return new UnknownCommand();
		}
	}
}
